import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

Vue.use(Vuex)

/* import course from "./modules/basics/course"; // 课程管理
import picture from "./modules/basics/picture"; // 课程管理
import classify from "./modules/basics/classify"; // 分类管理
import classGrade from "./modules/basics/classGrade" // 班级管理
import area from "./modules/educational/area" // 地区
import user from "./modules/user" // 用户


export default new Vuex.Store({
  state: {
  },
  mutations: {
  },
  actions: {
  },
  modules: {
    area,
    course,
    picture,
    classify,
    classGrade,
    user
  }
}) */


// https://webpack.js.org/guides/dependency-management/#requirecontext
const modulesFiles = require.context('./modules', true, /\.js$/)

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
    // eg: './basics/classGrade.js' => 'classGrade' || './user/index.js' => 'user'
    const moduleUrl = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1'); 
    let urlArr = moduleUrl.split('/');
    let moduleName = urlArr[urlArr.length - 1];
    moduleName = (moduleName == 'index') ? urlArr[0] : moduleName;
    const value = modulesFiles(modulePath)
    // console.log( `moduleName ${moduleName}` )
    // console.log( value )
    modules[moduleName] = value.default
    return modules
}, {}) 

const store = new Vuex.Store({
    modules,
    getters
})

export default store 